package cn.myjerry.map;

import java.util.HashMap;
import java.util.Map;

/**
 * 分拣存储： 1 => N
 * 统计单词出现次数
 * 
 * 1、分割字符串
 * 2、分拣存储
 * 3、按要求查看单词出现的次数  
 * 4、加入面向对象
 * @author Jerry
 *
 */

public class MapDemo02 {
	public static void main(String[] args) {
		//1、分割字符串
		String[] arr = "Whatever is worth doing is worth doing well .".split(" ");
		//2、分拣存储
		Map<String, Letter> map = new HashMap<String, Letter>();
		for(String key:arr) {
			if(!map.containsKey(key)) {
				map.put(key, new Letter(key));
			}
			Letter value = map.get(key);
			value.setCount(value.getCount() + 1);
		}
		for(String key:map.keySet()) {
			System.out.println(key+"==>"+map.get(key).getCount());
		}
	}
}
